<html>
<head><meta charset="utf-8"><title>How is parsing and analyzing after an edit done? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html">How is parsing and analyzing after an edit done?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195897243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195897243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195897243">(Apr 30 2020 at 20:31)</a>:</h4>
<p>I'm trying to understand how rust-analyzer updates the AST after an edit, and re-run or update analyses. I'm guessing it takes an incremental approach and doesn't re-run everything from scratch, but I'm not sure where to look for how this is implemented. Given an edit (say I turn a normal function into an async function by adding the keyword "async") how does rust-analyzer updates the AST, analysis results etc.? Which files/modules should I be looking at?</p>
<p>Thanks!</p>



<a name="195897399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195897399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195897399">(Apr 30 2020 at 20:32)</a>:</h4>
<p>The entry point here is <code>RootDatabase::apply_change</code> (<code>change.rs</code>)</p>



<a name="195897435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195897435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195897435">(Apr 30 2020 at 20:32)</a>:</h4>
<p>Though, that method is rather boring -- mostly is says "ok, now this file has this content"</p>



<a name="195897485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195897485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195897485">(Apr 30 2020 at 20:33)</a>:</h4>
<p>Figuring out which caches need to be invalidates is the job of salsa: <a href="https://github.com/salsa-rs/salsa" title="https://github.com/salsa-rs/salsa">https://github.com/salsa-rs/salsa</a></p>



<a name="195906357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195906357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195906357">(Apr 30 2020 at 21:48)</a>:</h4>
<p>Thanks! I'm trying to find where does re-parsing happen (after a <code>set_file_text_with_durability</code>). Presumely salsa calls rust-analyzer at some point, right? Which rust-analyzer function does it call with the new file contents?</p>



<a name="195942883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195942883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195942883">(May 01 2020 at 09:04)</a>:</h4>
<p>That would be <code>SourceDatabase::parse</code> function, defined in <code>ra_db/lib.rs</code></p>



<a name="195944889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195944889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195944889">(May 01 2020 at 09:37)</a>:</h4>
<p>Thanks! Where do I look for generation of red tree from a green tree?</p>



<a name="195945570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195945570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195945570">(May 01 2020 at 09:47)</a>:</h4>
<p>That would to <code>rowan</code> crate</p>



<a name="195945580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195945580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195945580">(May 01 2020 at 09:47)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rowan/tree/master/src" title="https://github.com/rust-analyzer/rowan/tree/master/src">https://github.com/rust-analyzer/rowan/tree/master/src</a></p>



<a name="195945596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195945596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195945596">(May 01 2020 at 09:47)</a>:</h4>
<p>green is green, cursor is red, violets are blue, naming is hard</p>



<a name="195948151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195948151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195948151">(May 01 2020 at 10:26)</a>:</h4>
<p>What is the reason for InternId to have type NonZeroU32 instead of u32 ? Optimizations?</p>



<a name="195948579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20is%20parsing%20and%20analyzing%20after%20an%20edit%20done%3F/near/195948579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20is.20parsing.20and.20analyzing.20after.20an.20edit.20done.3F.html#195948579">(May 01 2020 at 10:32)</a>:</h4>
<p>Yup, so that <code>Option&lt;InternId&gt;</code> takes 32 bits</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>